package io;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FlushDemo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("test.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        String line = "和我在成都的街头走一走, 哦哦哦哦哦~";
        byte[] data = line.getBytes(StandardCharsets.UTF_8);
        bos.write(data);
        /*
            flush:冲水

            flush()方法用于清空缓冲区，将缓冲输出流内部缓冲区中已经缓存的数据一次性写出
         */
        //bos.flush();
        System.out.println("写出完毕");

        //缓冲流的close中最后会进行一次flush动作
        bos.close();
    }
}
